package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;
import com.kaishengit.entity.Contactnote;
import com.kaishengit.entity.Employee;
import com.kaishengit.service.ContactService;
import com.kaishengit.service.ContactnoteService;

public class ContactAjax extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee employee = (Employee) session.getAttribute("employee");
		
		String eid = employee.getId();
		String cid = request.getParameter("contactid");
		String pid = (String)session.getAttribute("pid");
		
		com.kaishengit.entity.Contact contact = new ContactService().findById(cid);
		List<Contactnote>  recordlist = new ContactnoteService().findByContactIdAndEmployeeId(cid,eid);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("contact", contact);
		map.put("recordlist", recordlist);
		Gson gson = new Gson();
		String json = gson.toJson(map);
		response.setContentType("application/json;charset=UTF-8");
		
		PrintWriter out = response.getWriter();
		out.println(json);
		out.flush();
		out.close();
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
